<?php

namespace App\ServerLi;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
class TokenServer
{
    /**
     * Name:生成token
     * User: yangrui
     * Date: 2023/6/17
     * Time:8:43
     * @return string
     */
    public static function createToken(){
        $key = 'example_key';
        $payload = [
            'iss' => 'http://example.org',
            'aud' => 'http://example.com',
            'iat' => 1356999524,
            'nbf' => 1357000000,
        ];
        $jwt = JWT::encode($payload, $key, 'HS256');
        return $jwt;
    }

    /**
     * Name:解token
     * User: yangrui
     * Date: 2023/6/17
     * Time:8:43
     * @param string $jwt
     * @return false|\stdClass
     */
    public static function decodeToken(string $jwt){
        $key = 'example_key';
        $decoded = JWT::decode($jwt, new Key($key, 'HS256'));
        if($decoded){
            return $decoded;
        }else{
            return false;
        }
    }

}
